import service from "@/utils/request.js"

interface Book {
  id: string,
  name: string,
  imgUrl: string,
}

const SHELF_BASE_URL = "/bookshelf"

const addBookshelf = (username: string, book: Book) : Promise => {
  return service.request({
    method: "post",
    url: SHELF_BASE_URL + "/add",
    data: {
      username,
      id: book.id,
      name: book.name,
      imgUrl: book.imgUrl
    }
  })
}
      
const EXIST_KEY = "exist";

const existBook = (username: string, bookId: string) : Promise => {
  return service.request({
    method: "post",
    url: SHELF_BASE_URL + "/exist",
    data: {
      username,
      bookId
    }
  })
}

const removeFromBookshelf = (username: string, bookId: string) : Promise => {
  return service.request({
    method: "post",
    url: SHELF_BASE_URL + "/remove",
    data: {
      username,
      bookId
    }
  })
}

const getBooksFromShelf = (username: string) : Promise => {
  return service.request({
    method: "post",
    url: SHELF_BASE_URL + "/getBooks",
    data: {
      username
    }
  })
}

export { addBookshelf, removeFromBookshelf, existBook, getBooksFromShelf, EXIST_KEY }